package ltd.hxya.novel.analysis.controller;

import ltd.hxya.novel.analysis.feign.BookServiceFeign;
import ltd.hxya.novel.analysis.service.impl.HiveRowDataServiceImpl;
import ltd.hxya.novel.common.bean.Result;
import ltd.hxya.novel.entity.rowdata.DataPart;
import ltd.hxya.novel.entity.rowdata.WordAnalysis;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;
import java.sql.SQLException;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

@RestController
@RequestMapping("/analysis")
public class AnalysisController {

    @Autowired
    private HiveRowDataServiceImpl hiveRowDataService;

    @Autowired
    private BookServiceFeign bookServiceFeign;


    @GetMapping("getResult")
    public Result<List<List<DataPart>>> getResult() throws SQLException, IOException, ClassNotFoundException, InterruptedException {
        List<List<DataPart>> data = hiveRowDataService.analysisData();
        return Result.success(data);
    }

    @GetMapping("/bookGroup")
    public Result<Map<String,String>> bookGroup(){
        Map<String,String> bookGroupMap = hiveRowDataService.dataCategory();
        return Result.success(bookGroupMap);
    }

    @GetMapping("/categoryList")
    public Result<List<String>> categoryList(){
        Result<List<String>> result = bookServiceFeign.categoryList();
        return result;
    }

}
